package com.hyd.issues;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * (description)
 *
 * @author yiding.he
 */
public class AppConfiguration {

    private static Properties properties = new Properties();

    private static String rootPath;

    public static String getRootPath() {
        return rootPath;
    }

    public static void setRootPath(String path) throws IOException {
        rootPath = path;
        init(getConfigFile());
    }

    private static String getConfigFile() {
        return rootPath + "/WEB-INF/issues.properties";
    }

    public static void init(String path) throws IOException {
        properties.load(new FileInputStream(path));
    }

    public static String getString(String key) {
        return properties.getProperty(key);
    }

    public static boolean getBoolean(String key) {
        return "true".equalsIgnoreCase(getString(key));
    }

    public static void setBoolean(String key, boolean value) {
        try {
            properties.setProperty(key, String.valueOf(value));
            properties.store(new FileOutputStream(getConfigFile()), null);
        } catch (IOException e) {
            throw new AppException(e);
        }
    }
}
